/**************************************************************************** **
 * Copyright (C) 2001-2020 Inhand Networks, Inc.
 **************************************************************************** **/

/* ************************************************************************** **
 *     MODULE NAME            : system
 *     LANGUAGE               : C
 *     TARGET ENVIRONMENT     : Any
 *     FILE NAME              : mqtt_client.h
 *     FIRST CREATION DATE    : 2022/01/06
 * --------------------------------------------------------------------------
 *     Version                : 1.0
 *     Author                 : EExuke
 *     Last Change            : 2022/01/06
 *     FILE DESCRIPTION       : API exported to external moduels
** ************************************************************************** */
#ifndef _MQTT_CLIENT_H_
#define _MQTT_CLIENT_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mosquitto.h>
#include <jansson.h>

/*------------------Macro Definition-------------------------*/
/*#define MQTT_SERVER_ENDPOINT      "test.mosquitto.org"*/
#define MQTT_TOPIC_TEMPERATURE    "example/temperature"
#define MQTT_SERVER_ENDPOINT      "localhost"
#define DEF_USERNAME              "user1"
#define DEF_PASSWORD              "123456"

#define CTIOT_ENDPOINT            "mqtt.ctwing.cn"
#define CTIOT_TCP_PORT            1883
#define CTIOT_TLS_PORT            8883
#define CTIOT_CLIENT_ID           "151339742"
#define CTIOT_PASSWORD            "necfmqheJGxZClo2PUKdTWxNg9TCf5bvpcZLQmSNG4g"

#define CTIOT_TOPIC_SIZE          128

/*------------------End of Macro Definition------------------*/

int gl_mqtt_state;
struct mosquitto *gl_mosq;

typedef enum {
	MQTT_STATE_INIT = 0,
	MQTT_STATE_CONNECTING,
	MQTT_STATE_CONNECTED,
	MQTT_STATE_LOOP,
	MQTT_STATE_DISCONNECTED,
} MQTT_STATE;

typedef struct {
	const char topic[CTIOT_TOPIC_SIZE];
	void (*callback)(const struct mosquitto_message *msg);
} SUB_TOPIC_NODE;

/*------------------API Definition---------------------------*/
int mqtt_client_connect();
void mqtt_client_disconnect();
void general_msg_publish(char *topic, char *payload);
/*------------------End of API Definition--------------------*/

#endif /* End of _MQTT_CLIENT_H_ */

